package com.qinsong.myapplication.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.qinsong.myapplication.IMApplication;
/**
 * 保存，获取数据
 */
public class SpUtils {
    public static final String IS_NEW_INVITE ="is_new_invite" ;
    private static SpUtils instance = new SpUtils();
    private static SharedPreferences mSp;

    private SpUtils() {
    }
    //单例
    public static SpUtils getInstance() {
        if (mSp == null) {
            mSp = IMApplication.getGlobalApplication().getSharedPreferences("im", Context.MODE_PRIVATE);
        }
        return instance;
    }

    /**
     * 保存
     * @param key
     * @param value
     */
    public void save(String key,Object value){
        if (value instanceof  String){
            mSp.edit().putString(key, (String) value).commit();
        }else if (value instanceof Boolean){
            mSp.edit().putBoolean(key, (Boolean) value).commit();
        }else if (value instanceof Integer){
            mSp.edit().putInt(key, (Integer) value).commit();
        }
    }

    /**
     * 获取数据
     * @param key
     * @param defvalue
     * @return
     */
    public  String getString(String key,String defvalue){
        return mSp.getString(key,defvalue);
    }
    public Boolean getBoolean(String key,Boolean defvalue){
        return mSp.getBoolean(key,defvalue);
    }
    public int getInt(String key,int defvalue){
        return mSp.getInt(key,defvalue);
    }
}
